#include "globals.h"
#include "pcb.h"

PCB *get_pcb (UINT32 proc_ID) {
	UINT32 i;
	for(i = 0 ; i < NUM_PROCESSES ; i++)
	{
		if(pcbs[i].process_ID == proc_ID){	// Comes from initialization
			return &pcbs[i];
		}
	}
	// Put some debug statement here once it goes online
	return NULL;
}

VOID enqueue_message(PCB* pcb, MESSAGE* msg) {
	msg->next = NULL;
	if(pcb->message_queue_tail != NULL) {
		pcb->message_queue_tail->next = msg;
	} else {
		pcb->message_queue_head = msg;
	}
	pcb->message_queue_tail = msg;
}

MESSAGE* dequeue_message(PCB* pcb) {
	if(pcb->message_queue_head != NULL) {
		MESSAGE* msg;
		msg = pcb->message_queue_head;
		pcb->message_queue_head = msg->next;
		if(pcb->message_queue_head == NULL) {
			pcb->message_queue_tail = NULL;
		}
		msg->next = NULL;
		return msg;
	}
	return NULL;
}
